package com.yhd.mapper;

import com.yhd.domain.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author 二十
 * @since 2021/11/30 10:34 下午
 */
public interface UserMapper {

    @Select("select * from user")
    @Results(id = "userMap",
            value = {
                    @Result(id = true, column = "id", property = "userId"),
                    @Result(column = "username", property = "userName"),
                    @Result(column = "sex", property = "userSex"),
                    @Result(column = "address", property = "userAddress"),
                    @Result(column = "birthday", property = "userBirthday"),
                    @Result(column = "id", property = "accounts",
                            many = @Many(
                                    select = "com.yhd.mapper.AccountMapper.findById",
                                    fetchType = FetchType.LAZY
                            )
                    )
            })
    List<User> findAll();
    @Select("select * from user where id=#{id}")
    User findById(Integer id);
}
